package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.NanMessageTask;
import com.tsingtree.modular.mapper.NanMessageTaskMapper;
import com.tsingtree.modular.model.params.NanMessageTaskParam;
import com.tsingtree.modular.model.result.NanMessageTaskResult;
import  com.tsingtree.modular.service.NanMessageTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;


/**
 * <p>
 * 站内信任务 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-05-27
 */
@Service
public class NanMessageTaskServiceImpl extends ServiceImpl<NanMessageTaskMapper, NanMessageTask> implements NanMessageTaskService {

    @Override
    public void add(NanMessageTaskParam param){
        NanMessageTask entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanMessageTaskParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(NanMessageTaskParam param){
        NanMessageTask oldEntity = getOldEntity(param);
        NanMessageTask newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public NanMessageTaskResult findBySpec(NanMessageTaskParam param){
        return null;
    }

    @Override
    public List<NanMessageTaskResult> findListBySpec(NanMessageTaskParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(NanMessageTaskParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(NanMessageTaskParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private NanMessageTask getOldEntity(NanMessageTaskParam param) {
        return this.getById(getKey(param));
    }

    private NanMessageTask getEntity(NanMessageTaskParam param) {
        NanMessageTask entity = new NanMessageTask();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
